Attribute VB_Name = "CallStackOperations"
Option Explicit

Public vp_CallStackSessions As CallStackSessionManager

Public Function traceStringStackUsingDelimiter(ByVal pr_Stack As Stack, _
        ByVal pr_Delimiter As String) As String

Dim vl_Iterator As LLIterator
Dim vl_CurrentItem As Variant
Dim vl_Trace As String


checkAndHandleNonInitializedObject pr_Stack
checkAndHandleEmptyString pr_Delimiter

Set vl_Iterator = pr_Stack.getIterator

Do While Not IsEmpty(vl_Iterator.currentItem)
    assignVariantVariable vl_CurrentItem, vl_Iterator.currentItem
    vl_Trace = vl_Trace & vl_CurrentItem & pr_Delimiter
     vl_Iterator.moveNext
Loop

'Take off the last delimiter
If Len(vl_Trace) > 0 Then vl_Trace = Left(vl_Trace, Len(vl_Trace) - 1)

traceStringStackUsingDelimiter = vl_Trace
End Function


Public Function objectExistsInStack(ByVal pr_Stack As Stack, ByVal pr_Object As Object) As Boolean
Dim vl_StackIterator As LLIterator
Dim vl_ItemExists As Boolean

Set vl_StackIterator = pr_Stack.getIterator

Do While Not vl_StackIterator.currentItem Is Nothing
    If compareVariant(vl_StackIterator.currentItem, pr_Object) Then
        vl_ItemExists = True
        Exit Do
    End If
    vl_StackIterator.moveNext
Loop

objectExistsInStack = vl_ItemExists
End Function

Public Function removeandReturnObjectFromStackByObject(ByVal objectToRemove As Object, ByVal srcStack As Stack) As Object
Dim vl_StackIterator As LLIterator
Dim vl_objectRemoved As Object
Dim vl_Counter As Integer

Set vl_StackIterator = srcStack.getIterator

Do While IsEmpty(Not vl_StackIterator.currentItem)
    If Not vl_StackIterator.currentItem Is Nothing Then
        If objectToRemove = vl_StackIterator.currentItem Then
            Exit Do
        End If
    End If
    
    vl_Counter = vl_Counter + 1
    vl_StackIterator.moveNext
Loop

removeandReturnObjectFromStackByObject = srcStack.removeAndReturnByIndex(vl_Counter)
End Function

